#pragma once

#include "stdafx.h"

template <typename T> class CMyBuffer
{
private:
    T* m_lpBuffer;

public:
    CMyBuffer(DWORD dwSize)
    {
        m_lpBuffer = (T*)LocalAlloc(LPTR, sizeof(T) * dwSize);
    }

    CMyBuffer(T* szBuffer)
    {
        m_lpBuffer = szBuffer;
    }

    ~CMyBuffer()
    {
        if (m_lpBuffer != NULL)
        {
            LocalFree(m_lpBuffer);
        }
    }

    BOOL IsNull()
    {
        return m_lpBuffer == NULL;
    }

    T* GetBuffer()
    {
        return m_lpBuffer;
    }

    T* Detach()
    {
        T* result = m_lpBuffer;
        m_lpBuffer = NULL;
        return result;
    }
};

LPWSTR GetCurrentProcessFileName();
